package com.ag.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbOaContact;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbOaContact entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.ag.bean.TbOaContact
 * @author MyEclipse Persistence Tools
 */

public class TbOaContactDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbOaContactDAO.class);
	// property constants
	public static final String OA_NAME = "oaName";
	public static final String OA_DESCRI = "oaDescri";
	public static final String OA_GROUPS = "oaGroups";
	public static final String OA_GENDER = "oaGender";
	public static final String OA_SEX = "oaSex";
	public static final String OA_ID_CARD = "oaIdCard";
	public static final String OA_CODE = "oaCode";
	public static final String OA_QQ = "oaQq";
	public static final String OA_MSN = "oaMsn";
	public static final String OA_HOME_NUMBER = "oaHomeNumber";
	public static final String OA_OFFICE_NUMBER = "oaOfficeNumber";
	public static final String OA_EMAIL = "oaEmail";
	public static final String OA_PHONE_NUMBER = "oaPhoneNumber";
	public static final String OA_MOBILE_PHONE_NUMBER = "oaMobilePhoneNumber";
	public static final String OA_ADDRESS = "oaAddress";
	public static final String OA_ZIP_CODE = "oaZipCode";
	public static final String OA_CERTIFICATE_ID = "oaCertificateId";
	public static final String OA_POSITIONS = "oaPositions";
	public static final String OA_ROLES = "oaRoles";
	public static final String OA_IS_SHOW = "oaIsShow";

	protected void initDao() {
		// do nothing
	}

	public void save(TbOaContact transientInstance) {
		log.debug("saving TbOaContact instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbOaContact persistentInstance) {
		log.debug("deleting TbOaContact instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbOaContact findById(java.lang.String id) {
		log.debug("getting TbOaContact instance with id: " + id);
		try {
			TbOaContact instance = (TbOaContact) getHibernateTemplate().get(
					"com.ag.bean.TbOaContact", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbOaContact> findByExample(TbOaContact instance) {
		log.debug("finding TbOaContact instance by example");
		try {
			List<TbOaContact> results = (List<TbOaContact>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbOaContact instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbOaContact as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbOaContact> findByOaName(Object oaName) {
		return findByProperty(OA_NAME, oaName);
	}

	public List<TbOaContact> findByOaDescri(Object oaDescri) {
		return findByProperty(OA_DESCRI, oaDescri);
	}

	public List<TbOaContact> findByOaGroups(Object oaGroups) {
		return findByProperty(OA_GROUPS, oaGroups);
	}

	public List<TbOaContact> findByOaGender(Object oaGender) {
		return findByProperty(OA_GENDER, oaGender);
	}

	public List<TbOaContact> findByOaSex(Object oaSex) {
		return findByProperty(OA_SEX, oaSex);
	}

	public List<TbOaContact> findByOaIdCard(Object oaIdCard) {
		return findByProperty(OA_ID_CARD, oaIdCard);
	}

	public List<TbOaContact> findByOaCode(Object oaCode) {
		return findByProperty(OA_CODE, oaCode);
	}

	public List<TbOaContact> findByOaQq(Object oaQq) {
		return findByProperty(OA_QQ, oaQq);
	}

	public List<TbOaContact> findByOaMsn(Object oaMsn) {
		return findByProperty(OA_MSN, oaMsn);
	}

	public List<TbOaContact> findByOaHomeNumber(Object oaHomeNumber) {
		return findByProperty(OA_HOME_NUMBER, oaHomeNumber);
	}

	public List<TbOaContact> findByOaOfficeNumber(Object oaOfficeNumber) {
		return findByProperty(OA_OFFICE_NUMBER, oaOfficeNumber);
	}

	public List<TbOaContact> findByOaEmail(Object oaEmail) {
		return findByProperty(OA_EMAIL, oaEmail);
	}

	public List<TbOaContact> findByOaPhoneNumber(Object oaPhoneNumber) {
		return findByProperty(OA_PHONE_NUMBER, oaPhoneNumber);
	}

	public List<TbOaContact> findByOaMobilePhoneNumber(
			Object oaMobilePhoneNumber) {
		return findByProperty(OA_MOBILE_PHONE_NUMBER, oaMobilePhoneNumber);
	}

	public List<TbOaContact> findByOaAddress(Object oaAddress) {
		return findByProperty(OA_ADDRESS, oaAddress);
	}

	public List<TbOaContact> findByOaZipCode(Object oaZipCode) {
		return findByProperty(OA_ZIP_CODE, oaZipCode);
	}

	public List<TbOaContact> findByOaCertificateId(Object oaCertificateId) {
		return findByProperty(OA_CERTIFICATE_ID, oaCertificateId);
	}

	public List<TbOaContact> findByOaPositions(Object oaPositions) {
		return findByProperty(OA_POSITIONS, oaPositions);
	}

	public List<TbOaContact> findByOaRoles(Object oaRoles) {
		return findByProperty(OA_ROLES, oaRoles);
	}

	public List<TbOaContact> findByOaIsShow(Object oaIsShow) {
		return findByProperty(OA_IS_SHOW, oaIsShow);
	}

	public List findAll() {
		log.debug("finding all TbOaContact instances");
		try {
			String queryString = "from TbOaContact";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbOaContact merge(TbOaContact detachedInstance) {
		log.debug("merging TbOaContact instance");
		try {
			TbOaContact result = (TbOaContact) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbOaContact instance) {
		log.debug("attaching dirty TbOaContact instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbOaContact instance) {
		log.debug("attaching clean TbOaContact instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbOaContactDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TbOaContactDAO) ctx.getBean("TbOaContactDAO");
	}
}